# -*- coding:utf-8 -*-
from django.db import models
from django.contrib.auth.models import User
import datetime
from kao_question.models import *
from kao_class.models import *
from area.models import *


class kao_user(models.Model):
    class Meta:
        verbose_name=u'kaoala用户'
        verbose_name_plural = u'kaoala用户'

    user=models.OneToOneField(User)
    user_type=models.IntegerField(u'用户类型')   #0为后台管理员   1为老师  2为学生
    phone=models.CharField(u'手机号码',max_length=20,blank=True,null=True)
    imei = models.TextField(u'IMEI码', default=u'',blank=True, null=True)
    openid=models.TextField(u'第三方登录的openid',blank=True,null=True,default=u'')
    regsiter_type=models.IntegerField(u'注册的类型',default=0)  #0为使用默认方式   1为使用qq  2为使用新浪微薄  3为使用微信x
    invitecode=models.CharField(u'老师邀请码',max_length=20,default=u'',blank=True,null=True)
    entrance_time=models.DateField(u'高考时间',blank=True,null=True)

    def __unicode__(self):
        return self.user.username

class user_general_attribute(models.Model):
    class Meta:
        verbose_name=u'用户一般属性'
        verbose_name_plural = u'用户一般属性'

    user=models.ForeignKey(kao_user)
    father_id=models.IntegerField(u'父亲ID',blank=True,null=True)   #ID是kao_user的id
    coach_id=models.IntegerField(u'导师ID',blank=True,null=True)   #ID是kao_user的id
    school=models.CharField(u'学校',max_length=100,blank=True,null=True)
    son_id=models.TextField(u'子ID列表',blank=True,null=True)  #子的ID，每个子ID以","隔开   ID是kao_user的id
    sex = models.CharField(u'性别',choices=(('M','男'),('F','女')),max_length=1,blank=True,null=True)
    birthday=models.DateField(u'生日',default=datetime.datetime.now(),blank=True,null=True)
    badge_id=models.IntegerField(u'徽章ID',default=1,blank=True,null=True)
    # avatars_id=models.IntegerField(u'替身ID',default=1,blank=True,null=True)
    avatars_level=models.IntegerField(u'替身级别',default=1,blank=True,null=True)
    energry_point=models.IntegerField(u'血量值',default=0,blank=True,null=True)   #用户在网站内做一系列活动（看视频、做题）获取
    species=models.IntegerField(u'考A金币',default=0)   #kaoala金币  100个energry_point转化成一个金币
    in_class=models.ManyToManyField(kao_class,verbose_name=u'所在班级',blank=True,null=True)
    user_area=models.ForeignKey(area,verbose_name=u'生源',blank=True,null=True)
    avatar_path=models.TextField(null=True)
    # {face:'xxx',nose:'xxx',}

    def __unicode__(self):
        return self.user.user.username


class user_character(models.Model):
    class Meta:
        verbose_name=u'用户个性'
        verbose_name_plural = u'用户个性'

    user=models.ForeignKey(kao_user)
    warmth=models.IntegerField(u'乐群性',blank=True,null=True,default=0)
    intelligent=models.IntegerField(u'聪慧性',blank=True,null=True,default=0)
    stability=models.IntegerField(u'稳定性',blank=True,null=True,default=0)
    aggressiveness=models.IntegerField(u'恃强性',blank=True,null=True,default=0)
    excitatory=models.IntegerField(u'兴奋性',blank=True,null=True,default=0)
    perseverance=models.IntegerField(u'有恒性',blank=True,null=True,default=0)
    dare_to=models.IntegerField(u'敢为性',blank=True,null=True,default=0)
    sensitivity=models.IntegerField(u'敏感性',blank=True,null=True,default=0)
    suspicion=models.IntegerField(u'怀疑性',blank=True,null=True,default=0)
    fantasy=models.IntegerField(u'幻想性',blank=True,null=True,default=0)
    sophistication=models.IntegerField(u'世故性',blank=True,null=True,default=0)
    anxiety=models.IntegerField(u'忧虑性',blank=True,null=True,default=0)
    experimental=models.IntegerField(u'实验性',blank=True,null=True,default=0)
    Independence=models.IntegerField(u'独立性',blank=True,null=True,default=0)
    self_discipline=models.IntegerField(u'自律性',blank=True,null=True,default=0)
    tension=models.IntegerField(u'紧张性',blank=True,null=True,default=0)
    def __unicode__(self):
        return self.user.username



class user_performance(models.Model):
    class Meta:
        verbose_name=u'用户表现'
        verbose_name_plural = u'用户表现'

    user=models.ForeignKey(kao_user)
    sign_in_Frequency=models.IntegerField(u'登录频率',blank=True,null=False,default=0)
    finish_doc_last_week=models.IntegerField(u'上周完成文档课程数',blank=True,null=False,default=0)
    finish_movie_last_week=models.IntegerField(u'上周完成视频课程数',blank=True,null=False,default=0)
    answer_be_accepted=models.IntegerField(u'回答被采纳数',blank=True,null=False,default=0)
    ask_question_count=models.IntegerField(u'提问次数',blank=True,null=False,default=0)
    complete_exam_count=models.IntegerField(u'完成考试数',blank=True,null=False,default=0)
    ranking=models.IntegerField(u'当前成绩排名',blank=True,null=True,default=0) # 0为默认值(0不显示 or 显示作弊排名)
    last_use_time=models.DateTimeField(u'用户最后使用时间',default='',blank=True,null=True,help_text=u'用户最后使用时间，可用于大数据')
    last_login_time=models.DateTimeField(u'用户最后登陆服务器时间',default='',blank=True,null=True,help_text=u'用户最后登陆时间，可用于消息推送')

    def __unicode__(self):
        return self.user.username

'''
 以下是DOCTOR ning需求
? For each student:
– How much time he spends on each question                           每题所花时间：answer_question_detail
– Time stamp of each question                                        答每题时间戳：answer_question_detail
– Time stamp of each test subject                 -------------------过每一个考点的时间戳  generate
– How many questions he has answered, both correctly and incorrectly 答对多少题，答错多少题：answer_question_detail
– What are the difficulty level of each question he tries            答题难度汇总，尝试各种题目的次数：answer_question_detail + kao_question
– What are the test subjects that have been included                 包含了多少考点answer_question_detail + kao_question
? For a student who chooses to use recommendation system, other than what have been collected above:
– What is his accuracy when doing those questions.                   答题准确率answer_question_detail 字段计算可得 generate
– Complete sequence of his answer. (Order matters) ------------------学生答问题的序列 generate？

? For each question:关于题目
– How many time the questions is done                                 题目被被作答多少次
– How many time it is done correctly (difficult level)                题目被答对多少次
– How much time each student spends on this question (time consumption)---------题目对于每个学生所花时间 generate
Ning
'''

class answer_exam_f(models.Model):
    class Meta:
        verbose_name=u'回答试卷详情父表'
        verbose_name_plural = u'回答试卷详情父表'

    user=models.ForeignKey(kao_user)
    answer_exam_id=models.CharField(u'用户近来完成试卷列表',max_length=500,blank=True,null=True,default='',help_text=u'用户进来完成的考试列表，“;”分开，保存100个exam_id')

    def __unicode__(self):
        return self.user.username

class answer_exam_c(models.Model):
    class Meta:
        verbose_name=u'回答试卷详情子表'
        verbose_name_plural = u'回答试卷详情子表'

    user=models.ForeignKey(kao_user)
    exam_id=models.ForeignKey(kao_exam)
    begin_timestamp=models.DateField(u'开始时间戳',blank=True,null=True)
    end_timestamp=models.DateField(u'完成时间戳',blank=True,null=True)
    used_time=models.FloatField(u'答卷完成耗时',blank=True,null=True)
    def __unicode__(self):
        return self.user.username

class answer_question_detail(models.Model):
    class Meta:
        verbose_name=u'回答问题详情'
        verbose_name_plural = u'回答问题详情'

    user=models.ForeignKey(kao_user)
    question_id=models.ForeignKey(kao_question)
    answer_datetime=models.DateField(u'答题时间戳',default='',blank=True,null=True,help_text=u'答题时间戳')
    spend_on_question=models.FloatField(u'答题耗时',blank=True,null=True,help_text=u'答题耗时')
    answer_correct_count=models.IntegerField(u'回答正确次数',blank=True,null=True,default=0)
    answer_wrong_count=models.IntegerField(u'回答错误次数',blank=True,null=True,default=0)
    question_tried_list=models.TextField(u'所有回答问题列表',blank=True,null=True)
    knowlege_point_list=models.TextField(u'所有知识点列表',blank=True,null=True)
    def __unicode__(self):
        return self.user.username


class user_badge(models.Model):
    user=models.ForeignKey(kao_user)
    badge_list=models.CharField(u'奖励徽章ID',max_length=500,blank=True,null=True,default='0000')




class regsiter_code(models.Model):
    class Meta:
        verbose_name=u'获取验证码'
        verbose_name_plural=u'获取验证码'

    code_type=models.IntegerField(u'验证码类型',blank=True,null=True,default=0,help_text=u'1为找回密码时发送,0为用户注册')   #目前不使用此字段,不管是那个都默认为0
    phone=models.CharField(u'获取验证码手机号码',blank=True,null=True,default=u'',max_length=20,help_text=u'用户注册时申请验证码的手机号码')
    email=models.EmailField(u'获取验证码邮箱',blank=True,null=True,default=u'',help_text=u'用户注册时申请验证码的邮箱')
    code=models.CharField(u'验证码',max_length=6,blank=True,null=True,help_text=u'根据邮箱生成的对应验证码')
    create_datetime=models.DateTimeField(u'产生验证码时间',help_text=u'产生验证码时间')


    def __unicode__(self):
        return self.email



class invitecode(models.Model):
    class Meta:
        verbose_name=u'获取邀请码'
        verbose_name_plural=u'获取邀请码'

    code=models.CharField(u'老师邀请码',max_length=20,default=u'')
    userid=models.CharField(u'User表的用户id',max_length=50,blank=True,null=True,default=u'')
    username=models.CharField(u'用户名',max_length=30,blank=True,null=True,default=u'')
    phone=models.CharField(u'手机号码',max_length=20,blank=True,null=True,default=u'')
    is_use=models.IntegerField(u'是否使用过',default=0)   #0为邀请码未使用  1为邀请码已经使用
    create_time=models.DateTimeField(u'邀请码生成时间')

    def __unicode__(self):
        return self.code